opentelemetry-instrumentation-logging: add optional inject_trace_context argument for injecting trace context attributes#4626
Open
herin049 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an inject_trace_context option to opentelemetry-instrumentation-logging so trace correlation fields can be injected into LogRecord objects without forcing a logging.basicConfig() call (addressing the regression described in #4595).
Changes:
- Add
inject_trace_contextkwarg to enable trace context attribute injection without modifying logging configuration. - Update documentation to describe the two modes: injection-only vs injection +
basicConfig()formatting. - Add unit tests validating trace context injection via the new argument.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/init.py | Implements inject_trace_context logic and updates public docs/docstrings. |
| instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/constants.py | Updates rendered module documentation to explain the new injection-only path. |
| instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py | Adds tests verifying record attributes are injected when inject_trace_context=True. |
| .changelog/4626.added | Adds changelog entry for the new feature. |
xrmx
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the
opentelemetry-instrumentation-logginglibrary to include an optionalinject_trace_contextkeyword argument which allows for injection of trace context attributes for log records without setting the logging formatter.Fixes #4595
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.